﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace t4tesk1
{
    public partial class register : Form
    {
        public static SqlDataReader reader = null;
        public static string sql;
        public register()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //判断两次密码是否一致
            if (textBox2.Text!= textBox3.Text)
            {
                textBox4.Text = "与上一次输入密码不一致！";
            }
            else
            {
                //插入语句
                sql = string.Format("select * from User1");
                reader = DBHelper.Select(sql);
                while (reader.Read())
                {
                    //判断账号是否存在
                    if (textBox1.Text!=reader["UserName"].ToString())
                    {
                        sql = string.Format("insert User1(UserName,UserPwd) select '{0}','{1}'", textBox1.Text, textBox3.Text);
                        bool reader1 = DBHelper.GetNonQuery(sql);
                        MessageBox.Show("注册成功！");
                        break;
                    }
                    else if(textBox1.Text == reader["UserName"].ToString())
                    {
                        MessageBox.Show("账号已存在");
                        break;
                    }
                }
                
            }
        }
    }
}
